home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / NetFloat.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  3.9 KB  |  127 lines

  1. package symantec.itools.db.net;
  2.  
  3. import java.io.DataOutputStream;
  4. import java.io.IOException;
  5. import symjava.lang.Bignum;
  6. import symjava.sql.SQLException;
  7.  
  8. class NetFloat extends NumberField {
  9.    float _fVal;
  10.  
  11.    int getType() {
  12.       return 81;
  13.    }
  14.  
  15.    void readData(ServerObject data) throws SQLException, IOException, ErrorException {
  16.       this._fVal = ((NetData)data).getFloat();
  17.    }
  18.  
  19.    void writeData(DataOutputStream os) throws IOException {
  20.       NetData data = new NetData(this._fVal);
  21.       data.write(os);
  22.    }
  23.  
  24.    public String getString() throws SQLException {
  25.       return ((Field)this).isNull() ? null : String.valueOf(this._fVal);
  26.    }
  27.  
  28.    public boolean getBoolean() throws SQLException {
  29.       if (((Field)this).isNull()) {
  30.          return false;
  31.       } else {
  32.          return this._fVal != 0.0F;
  33.       }
  34.    }
  35.  
  36.    public byte getByte() throws SQLException {
  37.       return ((Field)this).isNull() ? 0 : (byte)((int)this._fVal);
  38.    }
  39.  
  40.    public short getShort() throws SQLException {
  41.       return ((Field)this).isNull() ? 0 : (short)((int)this._fVal);
  42.    }
  43.  
  44.    public int getInt() throws SQLException {
  45.       return ((Field)this).isNull() ? 0 : (int)this._fVal;
  46.    }
  47.  
  48.    public long getLong() throws SQLException {
  49.       return ((Field)this).isNull() ? 0L : (long)this._fVal;
  50.    }
  51.  
  52.    public float getFloat() throws SQLException {
  53.       return ((Field)this).isNull() ? 0.0F : this._fVal;
  54.    }
  55.  
  56.    public double getDouble() throws SQLException {
  57.       return ((Field)this).isNull() ? (double)0.0F : (double)this._fVal;
  58.    }
  59.  
  60.    public Bignum getBignum(int scale) throws SQLException {
  61.       return ((Field)this).isNull() ? null : new Bignum((double)this._fVal, scale);
  62.    }
  63.  
  64.    public void setBoolean(boolean x) throws SQLException {
  65.       if (x) {
  66.          this._fVal = 1.0F;
  67.       } else {
  68.          this._fVal = 0.0F;
  69.       }
  70.  
  71.       super._null = false;
  72.    }
  73.  
  74.    public void setByte(byte x) throws SQLException {
  75.       this._fVal = (float)x;
  76.       super._null = false;
  77.    }
  78.  
  79.    public void setShort(short x) throws SQLException {
  80.       this._fVal = (float)x;
  81.       super._null = false;
  82.    }
  83.  
  84.    public void setInt(int x) throws SQLException {
  85.       this._fVal = (float)x;
  86.       super._null = false;
  87.    }
  88.  
  89.    public void setLong(long x) throws SQLException {
  90.       this._fVal = (float)x;
  91.       super._null = false;
  92.    }
  93.  
  94.    public void setFloat(float x) throws SQLException {
  95.       this._fVal = x;
  96.       super._null = false;
  97.    }
  98.  
  99.    public void setDouble(double x) throws SQLException {
  100.       this._fVal = (float)x;
  101.       super._null = false;
  102.    }
  103.  
  104.    public void setBignum(Bignum x) throws SQLException {
  105.       this._fVal = x.floatValue();
  106.       super._null = false;
  107.    }
  108.  
  109.    public void setString(String x) throws SQLException {
  110.       Float i = new Float(x);
  111.       this._fVal = i;
  112.       super._null = false;
  113.    }
  114.  
  115.    public int getSQLType() {
  116.       return 6;
  117.    }
  118.  
  119.    public Object getObject() throws SQLException {
  120.       return new Double((double)this._fVal);
  121.    }
  122.  
  123.    public void setObject(Object obj) throws SQLException {
  124.       this.setDouble((Double)obj);
  125.    }
  126. }
  127.